#include <sys_config.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <hld/hld_dev.h>
#include <hld/dsc/dsc.h>

#ifdef DSC_DEBUG
#define DSC_DEBUG_PRINTF  libc_printf
#else
#define DSC_DEBUG_PRINTF(...) do{}while(0)
#endif

RET_CODE des_decrypt(pDES_DEV pDesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret = RET_FAILURE ;

   if(pDesDev == NULL)
       return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
       
   if (pDesDev->Decrypt)
   {
     ret = pDesDev->Decrypt( pDesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE des_encrypt(pDES_DEV pDesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
	RET_CODE ret = RET_FAILURE ;

	if(pDesDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
	   
	if (pDesDev->Encrypt)
	{
		ret = pDesDev->Encrypt( pDesDev, dmx_id,  input, output, total_length);
	}

	return ret;
}



RET_CODE des_ioctl( pDES_DEV pDesDev ,UINT32 cmd , UINT32 param)
{
    RET_CODE ret =  RET_FAILURE ;

    DSC_DEBUG_PRINTF("des_ioctl %x %x %x\n", pDesDev , cmd ,  param);

   if(pDesDev == NULL)
       return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
       
   if (pDesDev->Ioctl)
   {
		ret = pDesDev->Ioctl(pDesDev, cmd&0xff,  param);
   }
    return ret;  
}


RET_CODE aes_decrypt(pAES_DEV pAesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret = RET_FAILURE ;

   if(pAesDev == NULL)
       return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
       
   if (pAesDev->Decrypt)
   {
     ret = pAesDev->Decrypt( pAesDev, dmx_id,  input, output, total_length);
   }

   return ret;
}
RET_CODE aes_encrypt(pAES_DEV pAesDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
	RET_CODE ret = RET_FAILURE ;

	if(pAesDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;

	if (pAesDev->Encrypt)
	{
		ret = pAesDev->Encrypt( pAesDev, dmx_id,  input, output, total_length);
	}

	return ret;
}



RET_CODE aes_ioctl( pAES_DEV pAesDev ,UINT32 cmd , UINT32 param)
{
	RET_CODE ret = RET_FAILURE ;

	DSC_DEBUG_PRINTF("aes_ioctl %x %x %x\n", pAesDev , cmd ,  param);

	if(pAesDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;

	if (pAesDev->Ioctl)
	{
		ret = pAesDev->Ioctl(pAesDev, cmd&0xff,  param);
	}
	return ret;  
}
/*********************************************/



RET_CODE csa_decrypt(pCSA_DEV pCsaDev,UINT16 dmx_id,  UINT8 *input, UINT8 *output, UINT32 total_length)
{
   RET_CODE ret = RET_FAILURE ;

   if(pCsaDev == NULL)
       return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
       
   if (pCsaDev->Decrypt)
   {
     ret = pCsaDev->Decrypt( pCsaDev, dmx_id,  input, output, total_length);
   }

   return ret;
}



RET_CODE csa_ioctl( pCSA_DEV pCsaDev ,UINT32 cmd , UINT32 param)
{
   RET_CODE ret = RET_FAILURE ;

   DSC_DEBUG_PRINTF("csa_ioctl %x %x %x\n", pCsaDev , cmd ,  param);

   if(pCsaDev == NULL)
       return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;
       
   if (pCsaDev->Ioctl)
   {
		ret = pCsaDev->Ioctl(pCsaDev, cmd&0xff,  param);
   }
    return ret;  
}


RET_CODE sha_ioctl( pSHA_DEV pShaDev ,UINT32 cmd , UINT32 param)
{
	RET_CODE ret = RET_FAILURE ;

	DSC_DEBUG_PRINTF("sha_ioctl %x %x %x\n", pShaDev , cmd ,  param);

	if(pShaDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;

	if(pShaDev->Ioctl)
	{
		ret = pShaDev->Ioctl(pShaDev, cmd&0xff,  param);
	}
	return ret;  
}

RET_CODE sha_digest(pSHA_DEV pShaDev, UINT8 *input, UINT8 *output,UINT32 data_length)
{
	RET_CODE ret = RET_FAILURE ;
	DSC_DEBUG_PRINTF("%x,%x,%x,%x\n",pShaDev, input, output, data_length);

	if(pShaDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED ;

	if(pShaDev->digest)
	{
		ret = pShaDev->digest( pShaDev, input, output,data_length);
	}

	return ret ;
}

RET_CODE dsc_ioctl( pDSC_DEV pDscDev,UINT32 cmd , UINT32 param)
{
	RET_CODE ret = RET_FAILURE ;

	DSC_DEBUG_PRINTF("dsc_ioctl %x %x %x\n", pDscDev , cmd ,  param);

	if(pDscDev == NULL)
		return ALI_DSC_ERROR_DRIVER_NOT_INITIALIZED;

	if(pDscDev->ioctl)
	{
		ret = pDscDev->ioctl(pDscDev , cmd&0xff,  param);
	}
	return ret;  
}

